#include "process.h"
#include <time.h>
#include <stdlib.h>
#include <unistd.h>


typedef void(*Flush_t)(double current, double total);// 这是一个刷新的函数指针类型

double total = 2048.0; // 2048MB
int base = 100; 
double once = 0.5; // 0.1MB

//进度条的调用方式
void download(Flush_t f)
{
    // 模拟下载过程
    double current = 0.0;

    while(current < total)
    {
        int r = rand() % base + 1; // [1, 10]
        current += r * once;

        if(current >= total) current = total;
        usleep(50000);
        
        // 更新除本次新的下载量
        // 根据真实的应用场景，进行动态刷新
        //proce(current, total);
        f(current, total);

        //printf("%.1lf/%.1lf\r", current, total);
        //fflush(stdout);
        //usleep(5000);
    }

    printf("\n");
}

int main()
{
    srand(time(NULL));
    download(FlushProcess);
    //proce();

    return 0;
}







